﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using xIx.Web.UI;

public partial class PageTextEditor : PageBase
{
    public string BizID
    {
        get
        {
            object v = ViewState["BizID"];
            if (null != v)
            {
                return (string)v;
            }
            else
            {
                return default(string);
            }
        }
        set
        {
            ViewState["BizID"] = value;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BizID=Request["ID"];
            if (string.IsNullOrEmpty(BizID)) {
                SetPageDisable();
                return;
            }

            DataBind();
        }
    }
    protected void ResetButton_Click(object sender, ImageClickEventArgs e)
    {
        DataBind();
    }
    protected void SaveButton_Click(object sender, ImageClickEventArgs e)
    {
        DataTable dt = null;
        using (xIx.Data.DbHelper dh = new xIx.Data.DbHelper())
        {
            dt = dh.Table["Sys_PageTexts"].Where("ID=@RID").Select(BizID);

            if (dt.Rows.Count < 1)
            {
                SetPageDisable("载入数据失败。");
                return;
            }

            if (!FCKeditor1.Value.Equals(dt.Rows[0]["TextData"]))
            {
                try
                {
                    dh.Table["Sys_PageTexts"].Fields("TextData").UpdateWith(FCKeditor1.Value).Where("ID=@RID").Exec(BizID);
                }
                catch(Exception ex) {
                    Alert(ex.Message);
                }
            }
        }
        DataBind();
    }

    protected override void OnDataBinding(EventArgs e)
    {
        DataTable dt = null;
        using (xIx.Data.DbHelper dh = new xIx.Data.DbHelper())
        {
            dt = dh.Table["Sys_PageTexts"].Where("ID=@RID").Select(BizID);
        }
        if(dt.Rows.Count<1){
            SetPageDisable("载入数据失败。");
            return;
        }

        TextBox1.Text = dt.Rows[0]["ID"].ToString();
        TextBox2.Text = dt.Rows[0]["Title"].ToString();
        TextBox3.Text = dt.Rows[0]["Memo"].ToString();
        FCKeditor1.Value = dt.Rows[0]["TextData"].ToString();

        base.OnDataBinding(e);
    }

}
